package com.zy.algorithm.v2.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zy.algorithm.v2.R;
import com.zy.algorithm.v2.bean.CountSimpleNode;
import com.zy.algorithm.v2.bean.RadixSimpleNode;

public class RadixSortAdapter extends RecyclerView.Adapter<RadixSortAdapter.CountViewHolder> {

    int[] assist = new int[0];

    @NonNull
    @Override
    public CountViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int type) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.count_sort_item_layout, viewGroup, false);
        return new CountViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CountViewHolder viewHolder, int position) {
        viewHolder.bind(assist, position);
    }


    @Override
    public int getItemCount() {
        return assist.length;
    }

    public void setNode(RadixSimpleNode curNode) {
        this.assist = curNode.getAssist();
        notifyDataSetChanged();
    }

    public static class CountViewHolder extends RecyclerView.ViewHolder {
        TextView data;
        TextView size;

        public CountViewHolder(@NonNull View itemView) {
            super(itemView);
            data = itemView.findViewById(R.id.count_sort_item_layout_data);
            //data.setVisibility(View.GONE);
            size = itemView.findViewById(R.id.count_sort_item_layout_size);
        }

        public void bind(int[] assist, int position) {
            data.setText("" + (position));
            size.setText("" + assist[position]);
        }
    }
}
